import { CircleNode, CircleNodeModel, h } from "@logicflow/core";
import {shapeBorderColor} from "../../config";
import {NodeClassType} from "../../util/types";

class LEnd extends CircleNode {
    getShape() {
        const { model } = this.props;
        const { x, y, r } = model
        const { fill, stroke, strokeWidth } = model.getNodeStyle()
        return h('g', {},
            [
                h(
                    'circle',
                    {
                        cx: x,
                        cy: y,
                        r,
                        fill,
                        stroke,
                        strokeWidth
                    }
                ),
                h(
                    'circle',
                    {
                        cx: x,
                        cy: y,
                        r: r - 10,
                        fill,
                        stroke,
                        strokeWidth
                    }
                )
            ]
        )
    }

}

class KEndModel extends CircleNodeModel {
    initNodeData(data: any) {
        super.initNodeData(data);
        this.r = 50;
    }

    getNodeStyle() {
        const style = super.getNodeStyle();
        style.stroke = shapeBorderColor;
        style.fill = 'transparent';
        style.strokeWidth = 2;
        return style;
    }

    getConnectedSourceRules() {
        const rules = super.getConnectedSourceRules()
        const notAsTarget = {
            message: '终止节点不能作为连线的起点',
            validate: () => false
        }
        rules.push(notAsTarget)
        return rules
    }
}

export default<NodeClassType> {
    type: "LEnd",
    view: LEnd,
    model: KEndModel,
    text: '结束',
    icon: 'end',
    order: 2,
    properties: {}
}
